﻿# =============================
# 配置部分：根据你的实际路径修改
# =============================
$PROJECT_DIR = "D:\HW\first\LocalCacheManager"                          # 你的项目根目录
$DEVECO_SDK_HOME = "D:\Huawei\Harmony\DevEco Studio\tools\sdk"           # DevEco SDK 根目录
$HVIGOR_HOME = "$ENV:USERPROFILE\.hvigor"                                # Hvigor 缓存目录（可自定义）
$HVIGOR_BIN = "D:\Huawei\Harmony\DevEco Studio\tools\hvigor\bin"         # Hvigor 工具 bin 目录

# =============================
# 设置环境变量
# =============================
Write-Host "📌 正在设置环境变量..." -ForegroundColor Cyan

# 设置 DEVECO_SDK_HOME
$env:DEVECO_SDK_HOME = $DEVECO_SDK_HOME

# 设置 HVIGOR_HOME
$env:HVIGOR_HOME = $HVIGOR_HOME

# 将 Hvigor 添加到 PATH
$env:PATH += ";$HVIGOR_BIN"

# 创建 Hvigor 缓存目录（如果不存在）
if (-not (Test-Path -Path $HVIGOR_HOME)) {
    New-Item -ItemType Directory -Path $HVIGOR_HOME | Out-Null
    Write-Host "✅ 已创建 Hvigor 缓存目录: $HVIGOR_HOME" -ForegroundColor Green
}

# 切换到项目目录
Set-Location -Path $PROJECT_DIR

# 显示当前路径
Write-Host "📂 当前路径: $PROJECT_DIR" -ForegroundColor Green

# =============================
# 开始构建
# =============================
Write-Host "🚀 开始执行 hvigor 构建..." -ForegroundColor Yellow
hvigorw build

# 检查构建结果
if ($LASTEXITCODE -eq 0) {
    Write-Host "✅ 构建成功！" -ForegroundColor Green
} else {
    Write-Host "❌ 构建失败，请检查错误信息。" -ForegroundColor Red
}